import {
  CHANGEINPUTVALUE,
  CHANGELIST,
  LISTDELETE,
  INITLISTACTION,
  GETINITLIST
} from "./actiontypes";
import axios from "axios";



export const getInputValue = value => {
  return {
    type: CHANGEINPUTVALUE,
    value
  };
};

export const getChangeList = () => {
  return {
    type: CHANGELIST
  };
};

export const getListDelete = index => {
  return {
    type: LISTDELETE,
    index
  };
};
export const initListAction = data => {
    return {
        type: INITLISTACTION,
        data
    }
  
};
// 使用了redux-thunk后可以返回一个函数
export const getTodoList = () => {
    // 这里的return能够自动接收到store中的dispatch
  return (dispatch) => {
    axios.get('/api/todolist.json').then((res)=>{
        const data = res.data.data
        console.log(data)
        const action = initListAction(data)
        dispatch(action)
      })
  };
};

export const getInitList = ()=> {
    return {
        type: GETINITLIST
    }
}
